home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / C / Blitter / BounceLine.c next >
Encoding:
C/C++ Source or Header  |  1997-07-05  |  2.1 KB  |  85 lines

  1. /*
  2. ** Name:      BounceLine.c
  3. ** Author:    Paul Manias
  4. ** Copyright: DreamWorld Productions, 1997.
  5. ** Doc:       Line bouncing demo that works on a screen of any type of
  6. **            dimensions as specified by the user in GMSPrefs.
  7. **
  8. ** SAS/C:     1> sc BounceLine.c link startup=LIB:gms.o data=far nostackcheck
  9. ** Dice:      1> dcc -l0 -mD gms.o BounceLine.c -o BounceLine
  10. **
  11. */
  12.  
  13. #include <proto/games.h>
  14.  
  15. extern struct GMSBase *GMSBase;
  16. ULONG PREFSNAME = DEFAULT;
  17.  
  18. void main(void)
  19. {
  20.   struct GameScreen *GameScreen;
  21.   ULONG palette[] = { 0x000000,0x80f0f0 };
  22.   ULONG mousestat;
  23.   int sx,sy,ex,ey;
  24.   int dsx,dsy,dex,dey;
  25.  
  26.   if (AllocBlitter() == NULL) {
  27.     if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
  28.        GSA_Palette,palette,
  29.        GSA_AmtColours,2,
  30.        GSA_Attrib,DBLBUFFER,
  31.        TAGEND)) {
  32.  
  33.        sx = SlowRandom(GameScreen->ScrWidth);  dsx = -1;
  34.        sy = SlowRandom(GameScreen->ScrHeight); dsy = 2;
  35.        ex = SlowRandom(GameScreen->ScrWidth);  dex = 3;
  36.        ey = SlowRandom(GameScreen->ScrHeight); dey = 1;
  37.  
  38.        ShowScreen(GameScreen);
  39.  
  40.        do
  41.        {
  42.          ClearBitmap(GameScreen->Bitmap);
  43.          mousestat = ReadJoyPort(JPORT1,JT_ZBXY);
  44.          sx += dsx;
  45.          sy += dsy;
  46.          ex += dex;
  47.          ey += dey;
  48.  
  49.          if(sx<0) { sx = 0; dsx = -(dsx); }
  50.          if(sy<0) { sy = 0; dsy = -(dsy); }
  51.          if(ex<0) { ex = 0; dex = -(dex); }
  52.          if(ey<0) { ey = 0; dey = -(dey); }
  53.  
  54.          if(sx>GameScreen->ScrWidth-1) {
  55.            sx  = GameScreen->ScrWidth-1;
  56.            dsx = -(dsx);
  57.          }
  58.  
  59.          if(sy>GameScreen->ScrHeight-1) {
  60.            sy  = GameScreen->ScrHeight-1;
  61.            dsy = -(dsy);
  62.          }
  63.  
  64.          if(ex>GameScreen->ScrWidth-1) {
  65.            ex  = GameScreen->ScrWidth-1;
  66.            dex = -(dex);
  67.          }
  68.  
  69.          if(ey>GameScreen->ScrHeight-1) {
  70.            ey  = GameScreen->ScrHeight-1;
  71.            dey = -(dey);
  72.          }
  73.  
  74.          DrawUCLine(GameScreen->Bitmap,sx,sy,ex,ey,1);
  75.          WaitVBL();
  76.          SwapBuffers(GameScreen);
  77.        } while (!(mousestat & MB_LMB));
  78.  
  79.     DeleteScreen(GameScreen);
  80.     }
  81.   FreeBlitter();
  82.   }
  83. }
  84.  
  85.